//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  mixins: [scrollMixin], //加载更多
  components: {},
  data() {
  return {
    query:{
      student_keyword:'',
      status:'',
      page:1,
    },
    tabList: [
      {
        status: '',
        index: 0,
        name: "全部",
        
      },
      {
        status: 0,
        index: 1,
        name: "待付款",
       
      },
      {
        status: 3,
        index: 3,
        name: "已完成",
        
      },
      {
        status: -1,
        index: 4,
        name: "已关闭",
      }
    ],
    orderList:[],
    totalPage:0,
    isLoadMore: true,
    timer:null
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    orderSearch(detail) {
      this.student_keyword = detail;
      this.query.page = 1;
      this.goodsList()
    },
    onOrderChange(event) {
      this.query.page = 1;
      this.orderList = [];
      this.goodsList();
    },
    ondetails(item) {
      this.$router.push(
        this.fun.getUrl("orderdetail", {
          order_id: item.id,
          orderType: 'event-registration'
        })
      );
    },
    getorderState(args) {
      let { value, id, refundId, api } = args;
      let query = {
        apply_msg: () => {
          this.$router.push(this.fun.getUrl("gameDetails", {}, { orderIds: id }));
        }, //订单详情
        13: () => {
          //refundType: "2" 
          this.$router.push(
            this.fun.getUrl(
              "refund",
              {
                order_id: id,
                order_type: 1
              },
              { value: value }
            )
          );
        }, //申请售后
        1: () => {
          this.$router.push(this.fun.getUrl("orderpay", { order_ids: id, status: "2" }));
        }, //支付
        41: `${api}`, //客服
        //我的成绩
        my_score: () => {
          this.$router.push(this.fun.getUrl("myResult",{},{id:id}));
        }, //售后详情
        18: () => {
          this.$router.push(
            this.fun.getUrl("aftersales", {
              refund_id: refundId
            })
          );
        }
      };
      if (value.toString() === "9" || value.toString() === "12") {
        this.$dialog.confirm({
          title: "提示",
          message: value === 9 ? "确定取消该订单?" : "确定删除该订单?"
        })
          .then(() => {
            // on close
            value === 9 ? this.cancelPay(id, api) : this.deletePay(id, api);
          })
          .catch(() => {
            // on cancel
          }); //删除订单
      } else if (value.toString() === "41") {
        if (query[value]) {
          window.location.href = query[value];
        } else { 
          this.$toast('请设置客户链接');
        }
      }
      else {
        let paramsObj = query[value];
        return paramsObj.call(this);
      }
    },
    cancelPay(id, api) {
      let json = {
        order_id: id
      };
      $http.post(api, json, "正在获取").then(
        response => {
          if (response.result == 1) {
            this.$toast(response.msg);
            this.goodsList();
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    deletePay(id, api) {
      let json = {
        order_id: id
      };
      $http.post(api, json, "正在获取").then(
        response => {
          if (response.result == 1) {
            this.$toast(response.msg);
            this.goodsList();
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    goodsList() {
      $http.get("plugin.event-registration.api.order.order.index", this.query, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.isLoadMore = true;
            this.totalPage = res.last_page;
            if (!this.totalPage) {
              this.query.page = 0;
            }
            this.orderList = res.data;
          } else {
            this.query.page = this.query.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.query.page >= this.totalPage) {
        return;
      } else {
        this.query.page = this.query.page+1;
        $http.get("plugin.event-registration.api.order.order.index", this.query, "正在获取").then(
          response => {
            if (response.result == 1) {
              let res = response.data;
              let list = res.data;
              this.isLoadMore = true;
              this.orderList = [...this.orderList, ...list];
            } else {
              this.query.page = this.query.page - 1;
              this.isLoadMore = false;
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // console.log(response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.query.page = 1;
    this.orderList = [];
    this.goodsList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }